package com.xinlianshiye.im.bean

import org.hibernate.annotations.CreationTimestamp
import java.util.*
import javax.persistence.*

/**
 * 好友申请表
 *
 * @Author zw
 * @Description 好友申请表
 * @Date 9:21 2019/8/7
 * @Param
 */
@Entity
@Table(name = "im_applyuser")
class FriendApplication: Domain() {
    /**
     * 发送者 》》》关联用户
     */
    @ManyToOne
    @JoinColumn(name = "`from_user`", foreignKey = ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT), updatable = false, insertable = false)
    var user: User? = null

    @Column(name = "`from_user`")
    var userId: Int? = null

    /** 接受者 》》》关联用户  */
    @ManyToOne
    @JoinColumn(name = "`to_user`", foreignKey = ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT), updatable = false, insertable = false)
    var targetUser: User? = null

    @Column(name = "`to_user`")
    var targetUserId: Int? = null

    @Column(name = "status", columnDefinition = "tinyint(4) comment '申请状态 0: 待处理, 1: 同意, 2: 拒绝'")
    @Enumerated
    var applyState: ApplyStateEnum? = null

    @ManyToOne
    @JoinColumn(name = "`groupiden`", foreignKey = ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    var group // 发送者的 分组标识 》》》关联分组
            : UserGroup? = null

    @Column(columnDefinition = "varchar(255) comment '附言'")
    var postscript: String? = null

    @Column(columnDefinition = "varchar(255) comment '回复'")
    var reply: String? = null

    @Column(name = "state", columnDefinition = "tinyint(2) comment '表示对方的回复我是否已读，true代表读取过，false代表未读'")
    var haveRead: Boolean? = null

    @Column(name = "to_state", columnDefinition = "tinyint(2) comment '对方是否已读，true代表读取过，false代表未读'")
    var targetHaveRead: Boolean? = null

    /**
     * 申请状态
     */
    enum class ApplyStateEnum {
        /**
         * 待回复
         */
        Pending,

        /**
         * 同意
         */
        Agree,

        /**
         * 不同意
         */
        Reject
    }
}